<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    [v-cloak] {
      display: none;
    }
  </style>
</head>
<body>
  <div class="test">
    sdaskdahsdasd
    <span style="width: 100px;height: 100px;float: left;background: red;"></span>
  </div>
  <div id="app" v-cloak>
    {{ message }}
    <item v-if="comp === 1"></item>
    <item2 v-else></item2>
    <button @click="handleLogTime">生成时间</button>
  </div>
  <script src="https://lib.baomitu.com/vue/2.6.11/vue.js"></script>

  <script>
    let app = new Vue({
      // template: '<div id="root">{{ message }}</div>',
      components: {
        'item2': {
          beforeCreate() {
            console.log('beforeCreate child2')
          },
          created() {
            console.log('created child2')
          },
          beforeMount() {
            console.log('beforeMount child2')
          },
          mounted() {
            console.log('mounted child2')
          },
          render (h) {
            return h('div', '你好')
          }
        },
        'item': {
          beforeCreate() {
            console.log('beforeCreate child')
          },
          created() {
            console.log('created child')
          },
          beforeMount() {
            console.log('beforeMount child')
          },
          mounted() {
            console.log('mounted child')
          },
          beforeUpdate() {
            console.log('beforeUpdate child')
          },
          updated() {
            console.log('updated child')
          },
          beforeDestroy() {
            console.log('beforeDestroy child')
          },
          destroyed() {
            console.log('destroyed child')
          },
          activated() {
            console.log('activated child')
          },
          deactivated() {
            console.log('deactivated child')
          },
          errorCaptured (err, vm, info) {
            console.log('errorCaptured child')
            return false;
          },
          render (h) {
            console.log('render child.')
            throw new Error('render error')
          },
          renderError (h, err) {
            console.log('renderError child')
            return h('pre', { style: { color: 'red' }}, err.stack)
          }
        }
      },
      data: {
        message: 'Hello World!',
        comp: 1
      },
      computed: {
        getMessage: {
          get () {
            return Date.now()
          },
          cache: false
        },
        getMessage2: {
          get () {
            return Date.now()
          }
        }
      },
      watch: {
        message: [
          function (val) {
            console.log('1: ' + val)
          },
          function (val) {
            console.log('2: ' + val)
          },
          function (val) {
            console.log('3: ' + val)
          }
        ]
      },
      beforeCreate() {
        console.log('beforeCreate')
      },
      created() {
        setTimeout(() => {
          this.comp = 2
        }, 300)
        console.log('created')
      },
      beforeMount() {
        console.log('beforeMount')
      },
      mounted() {
        console.log('mounted')
        console.log(this.message, this.comp)
        setTimeout(() => {
          ({message: this.message, comp: this.comp} = {
            message: "析构赋值",
            comp: 3,
          })
          console.log(this.message, this.comp)
        }, 3000);
      },
      beforeUpdate() {
        console.log('beforeUpdate')
      },
      updated() {
        console.log('updated')
      },
      beforeDestroy() {
        console.log('beforeDestroy')
      },
      destroyed() {
        console.log('destroyed')
      },
      activated() {
        console.log('activated')
      },
      deactivated() {
        console.log('deactivated')
      },
      errorCaptured (err, vm, info) {
        console.log('errorCaptured')
        console.log('errorCaptured:', err)
        return false
      },
      renderError (h, err) {
        console.log('renderError')
        return h('pre', { style: { color: 'red' }}, err.stack)
      },
      methods: {
        handleLogTime() {
          console.log(this.getMessage, this.getMessage2)
        }
      }
    }).$mount('#app');
  </script>
</body>
</html>